<?php  
class adminModel extends Model{  
  
    function adminModel(){  
        parent::Model();  
    }  
  
    function getallannounce(){  
        $query=$this->db->get('announcement');
        if ($query-> num_rows() > 0){  
            foreach ($query->result() as $row){  
            $data[] = $row;  
            } 
        }			
        return $data;  
    }  
	
	function getfeatured(){
		$this->db->where('featured','yes');
        $query=$this->db->get('products');
        if ($query-> num_rows() > 0){  
            foreach ($query->result() as $row){  
            $data[] = $row;  
            } 
        }			
        return $data;  
	}
	
    function getallcat(){   
	    $query = $this->db->get('category');
        if ($query->num_rows() > 0){  
            foreach ($query->result() as $row){  
            $data[] = $row;  
            }  
        }  
        return $data;  
    }
	
	function getcategory($categid)
	{
		$this->db->where('prodcateg',$categid); 
		$query = $this->db->get('products');
		if ($query->num_rows() > 0){  
		foreach ($query->result() as $row){  
            $data[] = $row;  
            }  
			return $data;  
        }
		else
		{ return 0; }
        
	}
	
	function getcatname($categid)
	{
		$this->db->where('categid',$categid); 
		$query = $this->db->get('category');
        if ($query->num_rows() > 0){  
		foreach ($query->result() as $row){  
            $data[] = $row;  
            }  
        }  
        return $data;   
	}
	
	function getproduct($prodid)
	{
		$this->db->where('prodid',$prodid); 
		$query = $this->db->get('products');
		if ($query->num_rows() > 0){  
		foreach ($query->result() as $row){  
            $data[] = $row;  
            }  
        }  
        return $data;  
	}
	
	function validate_update_cart(){  
  
    // Get the total number of items in cart  
    $total = $this->cart->total_items();  
  
    // Retrieve the posted information  
    $item = $this->input->post('rowid');  
    $qty = $this->input->post('qty');  
  
    // Cycle true all items and update them  
    for($i=0;$i < $total;$i++)  
    {  
        // Create an array with the products rowid's and quantities.  
        $data = array(  
              'rowid' => $item[$i], 
              'qty'   => $qty[$i]  
           );  
  
           // Update the cart with the new information  
        $this->cart->update($data);  
		
    }  
  
	}
	function searchprod()
	{
		$keyword = $this->input->post('keyword');
		$this->db->like('prodname', $keyword); 
		$this->db->or_like('prodnote', $keyword); 
		$this->db->or_like('proddesc', $keyword); 
		$query =  $this->db->get('products');
		if ($query->num_rows() > 0){  
		foreach ($query->result() as $row){  
            $data[] = $row;  
            }
			return $data;
        } 
		else{
			return 0;
		}
	}
	
	function updateprod($prodid,$data){
			$this->db->where('prodid',$prodid);
			$this->db->update('books', $data);
		}
	function getalluser()
	{
		$query = $this->db->get('user');
		if ($query-> num_rows() > 0){  
            foreach ($query->result() as $row){  
            $data[] = $row;  
            } 
        }			
        return $data;  
	}
	function getcurpass($userid)
	{
		$this->db->where('userid',$userid);
		$this->db->select('password');
		$query = $this->db->get('user');
		if ($query-> num_rows() > 0){  
            foreach ($query->result() as $row){  
            $data[] = $row;  
            } 
        }			
        return $data;  
	}
	function getallpages()
	{
		$query = $this->db->get('pages');
        if ($query->num_rows() > 0){  
            foreach ($query->result() as $row){  
            $data[] = $row;  
            }  
        }  
        return $data;  
	}
	function getpage($pageid)
	{
		$this->db->where('pageid',$pageid);
		$query = $this->db->get('pages');
        if ($query->num_rows() > 0){  
            foreach ($query->result() as $row){  
            $data[] = $row;  
            }  
        }  
        return $data;  
	}
	
}

?>